<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <title>确认接机</title>
    </head>
    <body>
        <div id="seach_jj_form">
        </div>
        <div id="jj_ordersgrid" class="x-form-item">
        </div>
        <div id="jj_ticketsgrid" class="x-form-item">
        </div>
        <script>
            var current_order_id; //当前选择的order的id
            Ext.onReady(function(){
                var confirmStatus = new Ext.form.ComboBox({
                    store: new Ext.data.Store({
                        reader: new Ext.data.ArrayReader({}, ['value']),
                        data: [['所有'], ['未确认'], ['已确认'], ['已取消']]
                    }),
                    name: 'confirm_status',
                    fieldLabel: '接机状态',
                    resiable: true,
                    typeAhead: true,
                    width: 70,
                    handleHeight: 100,
                    displayField: 'value',
                    valueField: 'value',
                    nameField: 'confirm_status',
                    selectOnFocus: true,
                    mode: 'local',
                    selectOnFocus: true,
                    triggerAction: 'all', //这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
                    readOnly: true,
                    value: '所有'
                });
                var noField = new Ext.form.TextField({
                    fieldLabel: '订单编号',
                    name: 'order_no',
                    allowBlank: true,
                    anchor: '80%'
                });
                var jjDate = new Ext.form.DateField({
                    fieldLabel: '接机日期',
                    name: 'jjDate',
                    id: 'jj_date',
                    altFormats: 'Y-m-d',
                    format: 'Y-m-d', //格式化日期
                    //disabledDays: [0,6],	//不让选择周六，周日
                    //disabledDaysText: "周末要休息",
                    invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
                    allowBlank: false,
                    blankText: "起始日期不允许为空",
                    //emptyText: '请选择...',
                    inputType: '2008-01-01',
                    vtype: 'daterange',
                    endDateField: 'jj_date_to',
                    //anchor: '70%',
                    width: 90,
                    value: today
                });
                var jjDateTo = new Ext.form.DateField({
                    fieldLabel: '到',
                    name: 'jjDateTo',
                    id: 'jj_date_to',
                    altFormats: 'Y-m-d',
                    format: 'Y-m-d', //格式化日期
                    //disabledDays: [0,6],	//不让选择周六，周日
                    //disabledDaysText: "周末要休息",
                    invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
                    allowBlank: false,
                    blankText: "结束日期不允许为空",
                    //emptyText: '请选择...',
                    inputType: '2008-01-01',
                    vtype: 'daterange',
                    startDateField: 'jj_date',
                    //anchor: '70%',
                    width: 90,
                    value: today
                });
                
                var queryButton = new Ext.Button({
                    text: '查 询',
                    handler: function(){
                        orderDS.baseParams.no = noField.getValue();
                        orderDS.baseParams.jj_status = confirmStatus.getValue();
                        orderDS.baseParams.date = jjDate.getValue().format('Y-m-d');
                        orderDS.baseParams.date_to = jjDateTo.getValue().format('Y-m-d');
                        orderDS.reload();
                    }
                });
                
                var searchFormPanel = new Ext.form.FormPanel({
                    //baseCls: 'x-plain',
                    labelWidth: 65,
                    width: '100%',
                    frame: true,
                    labelAlign: 'right',
                    items: [{
                        layout: 'column',
                        border: false,
                        items: [{
                            columnWidth: .18,
                            layout: 'form',
                            border: false,
                            items: [jjDate]
                        }, {
                            columnWidth: .15,
                            labelWidth: 25,
                            layout: 'form',
                            border: false,
                            items: [jjDateTo]
                        }, {
                            columnWidth: .18,
                            layout: 'form',
                            border: false,
                            items: [confirmStatus]
                        }, {
                            columnWidth: .25,
                            layout: 'form',
                            border: false,
                            items: [noField]
                        }, {
                            columnWidth: .2,
                            layout: 'form',
                            border: false,
                            items: [queryButton]
                        }]
                    }]
                });
                
                searchFormPanel.render('seach_jj_form');
                
                //############## 订单Grid ##############
                var ordercm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
                    header: '编号',
                    dataIndex: 'id',
                    hidden: true
                }, {
                    header: '订单编号',
                    dataIndex: 'order_no',
                    sortable: true,
                    width: 120
                }, {
                    header: 'PNR',
                    dataIndex: 'pnr',
                    width: 50,
                    hidden: true
                }, {
                    header: '客户名称',
                    dataIndex: 'customer',
                    width: 70,
                    hidden: true
                }, {
                    header: '订单状态',
                    dataIndex: 'status',
                    width: 70,
                    hidden: true
                }, {
                    header: '接机日期',
                    dataIndex: 'fly_date',
                    sortable: true,
                    width: 70
                }, {
                    header: '接机时间',
                    dataIndex: 'jj_time',
                    sortable: true,
                    width: 60
                }, {
                    header: '起飞时间',
                    dataIndex: 'fly_time',
                    sortable: true,
                    width: 60
                }, {
                    header: '接机地址',
                    dataIndex: 'jj_address',
                    sortable: true,
                    width: 200
                }, {
                    header: '接机要求',
                    dataIndex: 'jj_request',
                    width: 120
                }, {
                    header: '接机人',
                    dataIndex: 'jj_man',
                    sortable: true,
                    width: 60
                }, {
                    header: '确认人',
                    dataIndex: 'jj_affirmer',
                    sortable: true,
                    width: 60
                }, {
                    header: '接机确认时间',
                    dataIndex: 'jj_affirm_date',
                    sortable: true,
                    width: 120,
                    renderer: Ext.util.Format.dateRenderer('Y-m-d H:i')
                }, {
                    header: '总金额',
                    dataIndex: 'price_sum',
                    sortable: true,
                    width: 60,
                    hidden: true
                }, {
                    header: '联系人',
                    dataIndex: 'link_man',
                    width: 60
                }, {
                    header: '联系电话',
                    dataIndex: 'link_tel',
                    width: 100
                }, {
                    header: '预定员',
                    dataIndex: 'creator',
                    width: 60,
                    hidden: true
                }, {
                    header: '预定时间',
                    dataIndex: 'created_at',
                    width: 120,
                    renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),
                    hidden: true
                }, {
                    header: '客户要求',
                    dataIndex: 'order_request',
                    width: 120
                
                }]);
                
                var orderDS = new Ext.data.Store({
                    proxy: new Ext.data.HttpProxy({
                        url: '/orders/getJJList'
                    }),
                    reader: orderReader
                });
                
                var ordergridpanel = new Ext.grid.GridPanel({
                    el: 'jj_ordersgrid',
                    ds: orderDS,
                    cm: ordercm,
                    //sm: sm,
                    loadMask: true,
                    autoWidth: true,
                    collapsible: true,
                    animCollapse: true,
                    height: 330,
                    //frame: true,
                    title: '接机信息',
                    bbar: new Ext.PagingToolbar({
                        pageSize: 10,
                        store: orderDS,
                        displayInfo: true,
                        displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
                        emptyMsg: "没有记录"
                    })
                
                });
                
                ordergridpanel.render();
                orderDS.load({
                    params: {
                        start: 0,
                        limit: 10
                    }
                })
                
                //双击订单查看票详细
                ordergridpanel.on('rowdblclick', function(ordergridpanel, rowIndex, e){
                    var current_order_selected = orderDS.data.items[rowIndex].id;
                    ordersrow = orderDS.getById(current_order_selected);//ds为绑定到grid的数据源 
                    current_order_id = ordersrow.get("id");
                    ticketDS.baseParams.id = current_order_id;
                    ticketDS.reload();
                });
                //订单右键菜单
                ordergridpanel.on('rowcontextmenu', function(customergridpanel, rowIndex, e){
                    var current_order_selected = orderDS.data.items[rowIndex].id;
                    ordersrow = orderDS.getById(current_order_selected);//ds为绑定到grid的数据源 
                    current_order_id = ordersrow.get("id");
                    e.preventDefault();
                    rightClick.showAt(e.getXY());
                });
                var rightClick = new Ext.menu.Menu({
                    items: [{
                        handler: rightMenu0Fn,
                        text: '【确认接机】'
                    }, {
                        handler: rightMenu1Fn,
                        text: '【取消接机】'
                    }]
                });
                function rightMenu0Fn(){
					var jj_request = ordersrow.get("jj_request");
                    if (jj_request.indexOf("已取消") >= 0) {
					    Ext.MessageBox.alert('提示信息', '该条记录已被取消');
					}
					else {
						affirmJJ();
					}
                }
				function rightMenu1Fn(){
					var jj_request = ordersrow.get("jj_request");
                    if (jj_request.indexOf("已取消") >= 0) {
					    Ext.MessageBox.alert('提示信息', '该条记录已被取消');
					}
					else {
						cancelJJ(current_order_id, orderDS, ticketDS);
					}
                }
                
                //### 机票Grid ###
                var ticketcm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
                    header: '编号',
                    dataIndex: 'id',
                    hidden: true
                }, {
                    header: 'PNR',
                    dataIndex: 'pnr',
                    width: 50
                }, {
                    header: '旅客姓名',
                    dataIndex: 'passenger_name',
                    width: 70
                }, {
                    header: '电话',
                    dataIndex: 'passenger_phone',
                    width: 120
                }, {
                    header: '证件号码',
                    dataIndex: 'card',
                    width: 140
                }, {
                    header: '票号',
                    dataIndex: 'ticket_no',
                    width: 110
                }, {
                    header: '状态',
                    dataIndex: 'status_type',
                    width: 60
                }, {
                    header: '出票状态',
                    dataIndex: 'status',
                    sortable: true,
                    width: 60
                }, {
                    header: '航班号',
                    dataIndex: 'airNo',
                    width: 60
                }, {
                    header: '航程',
                    dataIndex: 'fromto',
                    width: 60
                }, {
                    header: '乘机日期',
                    dataIndex: 'fly_date',
                    width: 70
                }, {
                    header: '起飞时间',
                    dataIndex: 'fly_time',
                    width: 60
                }, {
                    header: '舱位',
                    dataIndex: 'position',
                    width: 50
                }, {
                    header: '机票价格',
                    dataIndex: 'price',
                    width: 60
                }, {
                    header: '机场费税',
                    dataIndex: 'airdrome_tax',
                    width: 60
                }, {
                    header: '附加费',
                    dataIndex: 'fuel_tax',
                    width: 60
                }, {
                    header: 'F',
                    dataIndex: 'price_F',
                    width: 50
                }, {
                    header: '保险份数',
                    dataIndex: 'insurance_number',
                    width: 60
                }, {
                    header: '保险F',
                    dataIndex: 'insurance_F',
                    width: 50
                }, {
                    header: '其他',
                    dataIndex: 'other',
                    width: 50
                }, {
                    header: '积分',
                    dataIndex: 'point',
                    width: 50
                }, {
                    header: '合计',
                    dataIndex: 'total_price',
                    width: 70
                
                }]);
                
                var ticketProxy = new Ext.data.HttpProxy({
                    url: '/orders/getTicketsByOrderID'
                });
                
                var ticketDS = new Ext.data.Store({
                    proxy: ticketProxy,
                    reader: ticketReader
                });
                
                var ticketgridpanel = new Ext.grid.GridPanel({
                    el: 'jj_ticketsgrid',
                    ds: ticketDS,
                    cm: ticketcm,
                    loadMask: true,
                    autoWidth: true,
                    collapsible: true,
                    animCollapse: false,
                    height: 180,
                    //frame: true,
                    title: '机票列表'
                });
                
                ticketgridpanel.render();
                ticketDS.load();
                
                //确认接机
                function affirmJJ(){
                    var jj_man = new Ext.form.ComboBox({
                        store: new Ext.data.Store({
                            proxy: new Ext.data.HttpProxy({
                                url: '/users/getAllUsersComboBox'
                            }),
                            reader: new Ext.data.JsonReader({
                                root: 'root'
                            }, [{
                                name: 'id'
                            }, {
                                name: 'user_name'
                            }])
                        }),
                        fieldLabel: '接机人',
                        name: 'jj_man',
                        loadingText: '正在加载...',
                        displayField: 'user_name',
                        valueField: 'id',
                        mode: 'remote',
                        //hideTrigger: true,
                        triggerAction: 'all',
                        hiddenName: 'jj_man',//如果不想提交displayField，则在这儿指定以提交ID的值．
                        //hiddenId:'owner',
                        emptyText: '请选择...',
                        editable: false,
                        allowBlank: false,
                        blankText: "接机人必须选择",
                        //forceSelection: false,
                        width: 100,
                        //maxHeight: 150,
                        tabIndex: 4
                        /*
                         ,
                         listeners: {
                         select: function(combo, record, index){
                         //cityCombo.clearValue();
                         //cityCombo.store.loadData(record.data.city);
                         }
                         }
                         */
                    });
                    
                    var formPanel = new Ext.form.FormPanel({
                        baseCls: 'x-plain',
                        labelWidth: 75,
                        url: '/orders/affirmJJ?id=' + current_order_id,
                        defaultType: 'textfield',
                        items: jj_man
                    });
                    
                    var window = new Ext.Window({
                        title: '确认接机',
                        width: 300,
                        height: 120,
                        //minWidth: 300,
                        //minHeight: 120,
                        layout: 'fit',
                        plain: true,
                        bodyStyle: 'padding:5px;',
                        buttonAlign: 'center',
                        items: formPanel,
                        modal: true,
                        buttons: [{
                            text: '确认接机',
                            handler: function(){
                                if (formPanel.form.isValid()) {
                                    formPanel.form.submit({
                                        waitMsg: 'In processing',
                                        success: function(form, action){
                                            Ext.MessageBox.alert('提示信息', '操作成功');
                                            window.destroy();
                                            orderDS.reload();
                                        },
                                        failure: function(form, action){
                                            Ext.MessageBox.alert('提示信息', '操作失败');
                                        }
                                    });
                                }
                            }
                        }, {
                            text: '取消',
                            handler: function(){
                                window.destroy();
                            }
                        }]
                    });
                    
                    window.show();
                };
                })
        </script>
    </body>
</html>
